﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;

namespace ATSDAL
{
    public class PIMBatchReport : BaseRepository_DataSet, IPIMBatchReport
    {
        private const string PARM_TESTITEM_SN = "@ProductSN";
        private const string PARM_TESTITEM_TypeID = "@ProductTypeID";
        private const string PARM_TESTITEM_MO = "@MOID";
        private const string PARM_TESTITEM_TestType = "@TestStep";
        private const string PARM_TESTITEM_DataType = "@DataType";
        private const string PARM_TESTITEM_Date = "@TestDate";
        private const string PARM_TESTITEM_SDate = "@starttime";
        private const string PARM_TESTITEM_EDate = "@stoptime";
        private const string PARM_TESTITEM_UserID = "@UserID";


        // 根据条码获取交调数据
        public DataSet PIMData_ByProSN(string TableName, string ProSN)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_SN);
            testItemParms[0].Value = ProSN;

            return ExcuteDataset("PIM_Detail_BYProSN", TableName, testItemParms);
        }
        // 根据条码获取交调数据
        //public DataSet PIMData_ByProSN(string ProSN)
        //{
        //    SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_SN);
        //    testItemParms[0].Value = ProSN;

        //    return ExcuteDatasetP("PTITEM_Detail_BYProSN", testItemParms);
        //}

        // 根据产品型号获取交调数据
        //public DataSet PIMData_ByProTypeID(string ProTypeID)
        //{
        //    SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_TypeID);
        //    testItemParms[0].Value = ProTypeID;

        //    return ExcuteDatasetP("PTITEM_Detail_BYProTypeID", testItemParms);
        //}
        public DataSet PIMData_ByProTypeID(string TableName, string ProTypeID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_TypeID);
            testItemParms[0].Value = ProTypeID;

            return ExcuteDataset("PIM_Detail_BYProTypeID", TableName, testItemParms);
        }

        // 根据MO号获取交调数据

        //public DataSet PIMData_ByMO(string MOID)
        //{
        //    SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO);
        //    testItemParms[0].Value = MOID;

        //    return ExcuteDatasetP("PTITEM_Detail_BYMO", testItemParms);
        //}
        public DataSet PIMData_ByMO(string TableName, string MOID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO);
            testItemParms[0].Value = MOID;

            return ExcuteDataset("PIM_Detail_BYMO", TableName, testItemParms);
        }

        // 根据MO和时间段获数据

        public DataSet PTData_ByMO(string TableName,string MOID, string sDt, string eDt)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO, PARM_TESTITEM_SDate, PARM_TESTITEM_EDate);
            testItemParms[0].Value = MOID;
            testItemParms[1].Value = sDt;
            testItemParms[2].Value = eDt;

            return ExcuteDataset("PIM_Detail_BYProTypeIDandDate", TableName, testItemParms);
        }


        public DataSet PTData_ByUserIDandDte(string TableName, string UserID, string sDt, string eDt) 
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_UserID, PARM_TESTITEM_SDate, PARM_TESTITEM_EDate);
            testItemParms[0].Value = UserID;
            testItemParms[1].Value = sDt;
            testItemParms[2].Value = eDt;

            return ExcuteDataset("PIM_Detail_BYUserandDate", TableName, testItemParms);
        }

        public DataSet PTData_ByDate(string TableName, string sDt, string eDt) 
        {
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = sDt;
            testParms[1].Value = eDt;
            return ExcuteDataset("PIM_Detail_BYDate", TableName, testParms);
        } 


        //查询所有数据
        public DataSet AllDate()
        {
            return Execute("PTITEM_Detail_All");
        }




        #region 参数部分
        private static SqlParameter[] GetSNTParameters(string Par)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par, SqlDbType.Text),           
                };
            return parms;
        }

        private static SqlParameter[] GetSNTParameters(string Par1, string Par2, string Par3)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par1, SqlDbType.Text), 
                    new SqlParameter(Par2, SqlDbType.DateTime, 8),
                    new SqlParameter(Par3, SqlDbType.DateTime, 8) 
                };
            return parms;
        }

        private static SqlParameter[] GetSNTParameters(string Par1, string Par2, string Par3, string Par4)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par1, SqlDbType.Text), 
                    new SqlParameter(Par2, SqlDbType.Text),
                    new SqlParameter(Par3, SqlDbType.Text),
                    new SqlParameter(Par4, SqlDbType.DateTime, 8),
                };
            return parms;
        }

        public SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TESTITEM_SDate, SqlDbType.DateTime,8),
                    new SqlParameter(PARM_TESTITEM_EDate, SqlDbType.DateTime,8),
                };
            return parms;
        }
        #endregion


        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------


        #endregion
    }
}